home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Online / NNTPd / server / ihave.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-01  |  2.7 KB  |  132 lines

  1. #ifndef lint
  2. static char    sccsid[] = "@(#)$Id: ihave.c,v 1.20 1994/11/01 06:08:21 sob Exp sob $";
  3. #endif
  4.  
  5. #include "common.h"
  6. #ifdef MSGID
  7. #include "msgid.h"
  8. #endif
  9.  
  10. #ifdef LOG
  11. int    ih_accepted;
  12. int    ih_rejected;
  13. int    ih_failed;
  14. #endif
  15.  
  16. /*
  17.  * IHAVE <messageid>
  18.  *
  19.  * Accept an article for transferral if we haven't seen it before.
  20.  */
  21.  
  22. void
  23. ihave(argc, argv)
  24.     int        argc;
  25.     char        *argv[];
  26. {
  27.     char        errbuf[2 * NNTP_STRLEN];
  28.     int        retcode;
  29.     register char    *cp;
  30. #ifdef MSGID
  31.     int        dup = 0;
  32. #endif
  33.   
  34.     if (!canxfer)
  35.         {
  36. #ifdef LOG
  37.         syslog(LOG_INFO, "%s ihave attempted without permission",
  38.             hostname);
  39. #endif
  40.         printf("%d You do not have transfer permission\r\n",
  41.             ERR_GOODBYE);
  42.         (void) fflush(stdout);
  43.         return;
  44.         }
  45.  
  46.     if (argc != 2) {
  47.         printf("%d Usage: IHAVE <message-id>.\r\n", ERR_CMDSYN);
  48.         (void) fflush(stdout);
  49.         return;
  50.     }
  51.  
  52. #ifdef MSGID
  53.     if (msgid(argv[1], MADD))
  54.         dup++;
  55.  
  56.     if (!dup) {
  57.         cp = gethistent(argv[1], 1);
  58.         if (cp != NULL) {
  59.             dup++;
  60.             (void) msgid(argv[1], MOLD);
  61.         }
  62.     }
  63.     if (dup) {
  64. #else
  65.     cp = gethistent(argv[1], 1);
  66.     if (cp != NULL) {
  67. #endif /*MSGID*/
  68.         printf("%d Got it.\r\n", ERR_GOTIT);
  69.         (void) fflush(stdout);
  70. #ifdef LOG
  71.         ih_rejected++;
  72. #ifdef IHAVE_DEBUG
  73.         syslog(LOG_DEBUG, "%s ihave %s rejected", hostname, argv[1]);
  74. #endif
  75. #endif
  76.         return;
  77.     }
  78.  
  79.     if (!space(MINFREE)) {
  80.         /* force error reporting code into sending */
  81.         /* an out-of-space error message           */
  82.         if (gethostname(errbuf, MAXHOSTNAMELEN) < 0)
  83.         (void) strcpy(errbuf, "Amnesiac");
  84.  
  85.         (void) strcat(errbuf, " NNTP server out of space. Try later.");
  86.  
  87.         retcode = 0;        /* indicates that an error occurred */
  88.     } else 
  89. #ifdef BATCHED_INPUT
  90.         /* C news input hook */
  91.         retcode = batch_input_article(CONT_XFER, ERR_XFERFAIL,
  92.         errbuf, argv[1]);
  93. #else
  94.         retcode = spawn(rnews, "rnews", (char *) 0, CONT_XFER,
  95.         ERR_XFERFAIL, errbuf, argv[1]);
  96. #endif
  97.  
  98.     if (retcode <= 0){
  99.                /* Reject if "*:<optional_whitespace>inbound*", else fail */
  100.                register int i;
  101.  
  102. #ifdef MSGID
  103.            (void) msgid(argv[1], MCANCEL);
  104. #endif
  105.  
  106.                i = ERR_XFERFAIL;
  107.                if (cp = index(errbuf,':')) {
  108.                        for (++cp; isspace(*cp); ++cp)
  109.                                ;
  110.                        if (strncasecmp(cp, "inbound", 7) == 0)
  111.                                i = ERR_XFERRJCT;
  112.                }
  113.                printf("%d %s\r\n", i, errbuf);
  114.        }
  115.         else
  116.                printf("%d Thanks.\r\n", OK_XFERED);
  117.         (void) fflush(stdout);
  118.  
  119. #ifdef LOG
  120.     if (retcode == 1)
  121.         ih_accepted++;
  122.     else
  123.         ih_failed++;
  124.         
  125. #ifdef IHAVE_DEBUG
  126.     syslog(LOG_DEBUG, "%s ihave %s accepted %s",
  127.         hostname, argv[1], retcode == 1 ? "succeeded" : "failed");
  128. #endif
  129. #endif /* LOG */
  130.  
  131. }
  132.